let app = getApp() 
Page({
  data:{
    store_info:'',
    num:0,
    is_favorate:false,
	shop_data: ''
  },
  onLoad:function(option){
    var that = this
    var shop_id = option.shop_id
    if (!shop_id){
      shop_id = that.data.shop_id
    }
    // toast组件实例
    new app.ToastPannel();
    var k = wx.getStorageSync('key');
    var u = wx.getStorageSync('u');
    if(u){
      wx.request({
        url: app.configData.shop.api_url + '/index.php?ctl=Shop&met=getStoreIntro&typ=json',
        method: 'GET',
        data: {
          k: k,
          u: u,
          shop_id:shop_id,
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          that.setData({
            store_info: res.data.data.store_info,
			shop_data: res.data.data.shop_data,
            k:k,
            u:u,
            shop_id: shop_id,
            num: res.data.data.store_info.shop_collect,
            is_favorate: res.data.data.store_info.is_favorate
          })
        }
      })
    }
    
  },
  
  // 预览图片
   previewImage() {
     wx.previewImage({
       current: this.data.shop_data, // 当前显示图片的http链接
       urls: [this.data.shop_data] // 需要预览的图片http链接列表
     });
   },
  
  //取消收藏店铺
  is_favo: function () {
    var that = this
    var k = wx.getStorageSync('key');
    var u = wx.getStorageSync('u');
    wx.request({
      url: app.configData.shop.api_url + '/index.php?ctl=Buyer_Favorites&met=delFavoritesShop&typ=json',
      method: 'GET',
      data: {
        k: k,
        u: u,
        id: that.data.shop_id
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {

        that.show('已取消收藏');
        that.setData({
          is_favorate: false,
          num: Number(that.data.num) - 1
        })
      }
    })
  },
  //收藏店铺
  if_favo: function () {
    var that = this
    var k = wx.getStorageSync('key');
    var u = wx.getStorageSync('u');
    if (!k) {
      that.show("您还未绑定商城系统，请重新绑定")
    } else {
      wx.request({
        url: app.configData.shop.api_url + '/index.php?ctl=Shop&met=addCollectShop&typ=json',
        method: 'GET',
        data: {
          k: k,
          u: u,
          shop_id: that.data.shop_id
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {

          that.show('已收藏');
          that.setData({
            is_favorate: true,
            num: Number(that.data.num) + 1
          })
        }
      })
    }
  },
})